package com.ruoyi.pc.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.pc.domain.LbWxuserDevice;
import com.ruoyi.pc.service.ILbWxuserDeviceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 微信用户和设备关联关系Controller
 * 
 * @author ruoyi
 * @date 2020-06-21
 */
@RestController
@RequestMapping("/wxuserdevice")
public class LbWxuserDeviceController extends BaseController
{
    @Autowired
    private ILbWxuserDeviceService lbWxuserDeviceService;

    /**
     * 查询微信用户和设备关联关系列表
     */
    @PreAuthorize("@ss.hasPermi('business:wxuserdevice:list')")
    @GetMapping("/list")
    public TableDataInfo list(LbWxuserDevice lbWxuserDevice)
    {
        startPage();
        List<LbWxuserDevice> list = lbWxuserDeviceService.selectLbWxuserDeviceList(lbWxuserDevice);
        return getDataTable(list);
    }

    /**
     * 导出微信用户和设备关联关系列表
     */
    @PreAuthorize("@ss.hasPermi('business:wxuserdevice:export')")
    @Log(title = "微信用户和设备关联关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LbWxuserDevice lbWxuserDevice) throws IOException
    {
        List<LbWxuserDevice> list = lbWxuserDeviceService.selectLbWxuserDeviceList(lbWxuserDevice);
        ExcelUtil<LbWxuserDevice> util = new ExcelUtil<LbWxuserDevice>(LbWxuserDevice.class);
        util.exportExcel(response, list, "wxuserdevice");
    }

    /**
     * 获取微信用户和设备关联关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:wxuserdevice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(lbWxuserDeviceService.selectLbWxuserDeviceById(id));
    }

    /**
     * 新增微信用户和设备关联关系
     */
    @PreAuthorize("@ss.hasPermi('business:wxuserdevice:add')")
    @Log(title = "微信用户和设备关联关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LbWxuserDevice lbWxuserDevice)
    {
        return toAjax(lbWxuserDeviceService.insertLbWxuserDevice(lbWxuserDevice));
    }

    /**
     * 修改微信用户和设备关联关系
     */
    @PreAuthorize("@ss.hasPermi('business:wxuserdevice:edit')")
    @Log(title = "微信用户和设备关联关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LbWxuserDevice lbWxuserDevice)
    {
        return toAjax(lbWxuserDeviceService.updateLbWxuserDevice(lbWxuserDevice));
    }

    /**
     * 删除微信用户和设备关联关系
     */
    @PreAuthorize("@ss.hasPermi('business:wxuserdevice:remove')")
    @Log(title = "微信用户和设备关联关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(lbWxuserDeviceService.deleteLbWxuserDeviceByIds(ids));
    }
}
